GtkStack: add gtk_stack_get_child_by_name()
authorSteve Frécinaux <code@istique.net>
Mon, 20 Jan 2014 08:32:37 +0000 (09:32 +0100)
committerSteve Frécinaux <code@istique.net>
Tue, 21 Jan 2014 08:35:22 +0000 (09:35 +0100)
This new method allows getting a widget from a GtkStack when we know its
name, and will also return NULL if there is no widget going by that
name.

Usage example would be to check if a child with a given name exists
before calling gtk_stack_set_visible_child_name().

https://bugzilla.gnome.org/show_bug.cgi?id=722588

gtk/gtkstack.c
gtk/gtkstack.h

index 1c61192df7266e9183dd31b32f11579d6c0a4b32..f158d134e5c7e55ffeff1f6c78296d28299d3a3f 100644 (file)
@@ -1133,6 +1133,40 @@ gtk_stack_remove (GtkContainer *container,
     gtk_widget_queue_resize (GTK_WIDGET (stack));
 }
 
+/**
+ * gtk_stack_get_child_by_name:
+ * @stack: a #GtkStack
+ * @name: the name of the child to find
+ *
+ * Finds the child of the #GtkStack with the name given as
+ * the argument. Returns %NULL if there is no child with this
+ * name.
+ *
+ * Return value: (transfer none): the requested child of the #GtkStack
+ *
+ * Since: 3.12
+ */
+GtkWidget *
+gtk_stack_get_child_by_name (GtkStack    *stack,
+                             const gchar *name)
+{
+  GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
+  GtkStackChildInfo *info;
+  GList *l;
+
+  g_return_val_if_fail (GTK_IS_STACK (stack), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  for (l = priv->children; l != NULL; l = l->next)
+    {
+      info = l->data;
+      if (info->name && strcmp (info->name, name) == 0)
+        return info->widget;
+    }
+
+  return NULL;
+}
+
 /**
  * gtk_stack_set_homogeneous:
  * @stack: a #GtkStack
index d0bb47188a269dd7fd04d6fcdde2dd2b734bcfa9..edecf7f5a38fb4b03c0193dda13affc6732e6b20 100644 (file)
@@ -79,6 +79,9 @@ void                   gtk_stack_add_titled              (GtkStack
                                                           GtkWidget              *child,
                                                           const gchar            *name,
                                                           const gchar            *title);
+GDK_AVAILABLE_IN_3_12
+GtkWidget *            gtk_stack_get_child_by_name       (GtkStack               *stack,
+                                                          const gchar            *name);
 GDK_AVAILABLE_IN_3_10
 void                   gtk_stack_set_visible_child       (GtkStack               *stack,
                                                           GtkWidget              *child);